﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pokemon
{
    enum MoveType
    {
        Physical,
        Special,
        Status,
    }

    enum EffectType
    {
        Poison,
    }

    class Move
    {
        public string Name;
        public int Power;
        public int Accuracy;
        public int PP;
        public int MaxPP;
        public int Duration;
        public MoveType Type;
        public PokeType Element;
        public List<EffectType> Active = new List<EffectType>();
        public List<EffectType> Passive = new List<EffectType>();

        public void ActiveEffect(Pokemon target, Pokemon user)
        {
        }

        public void PassiveEffect(Pokemon target, Pokemon user)
        {
            foreach (EffectType effect in Passive)
            {
                switch (effect)
                {
                    case(EffectType.Poison):

                        break;
                }
            }
        }

        public int CalculateDamage(Pokemon target, Pokemon user)
        {
            int Attack,Defense;
            double STAB = 1;
            double TypeEffect = Global.GetTypeEffect(Element,target.Types[0]);
            if (target.Types[0] != null)
            {
                TypeEffect *= Global.GetTypeEffect(Element, target.Types[1]);
            }
            double Critical = 1;
            double Other = 1;

            

            switch (Type)
            {
                case (MoveType.Physical):
                    Attack = user.ATK;
                    Defense = user.DEF;
                    break;
                case (MoveType.Special):
                    Attack = user.SPATK;
                    Defense = user.SPDEF;
                    break;
                default:
                    Attack = 0;
                    Defense = 0;
                    break;
            }

            double Modifier = STAB * TypeEffect * Critical * Other * (Global.Random.Next(85,100) / 100);
            double BaseDamage = (((2 * user.Level + 10) / 250) * (Attack / Defense) * Power + 2);

            return (int)(BaseDamage * Modifier);
        }

        public double CalculateOther(Pokemon target, Pokemon user)
        {
            double Other = 1;

            if (user.Ability.Contains(PokeAbility.Blaze) && user.CurrentHP < (user.MaxHP / 3) && Element == PokeType.Fire)
            {
                Other *= 1.5;
            }

            if (user.Ability.Contains(PokeAbility.Torrent) && user.CurrentHP < (user.MaxHP / 3) && Element == PokeType.Water)
            {
                Other *= 1.5;
            }

            if (user.Ability.Contains(PokeAbility.Overgrow) && user.CurrentHP < (user.MaxHP / 3) && Element == PokeType.Grass)
            {
                Other *= 1.5;
            }

            if (user.Ability.Contains(PokeAbility.Swarm) && user.CurrentHP < (user.MaxHP / 3) && Element == PokeType.Bug)
            {
                Other *= 1.5;
            }

            if (user.Ability.Contains(PokeAbility.Guts))
            {
                Other *= 2;
            }

            return Other;
        }
    }
}
